package main

import (
	"log"
	"time"

	binance_connector "github.com/binance/binance-connector-go"
)

func main() {
	// 创建websocketclient
	wssc := binance_connector.NewWebsocketStreamClient(false)

	// 处理订阅成功的数据
	wdh := func(event *binance_connector.WsDepthEvent) {
		log.Println(binance_connector.PrettyPrint(event))
	}

	// 处理异常
	errh := func(err error) {
		log.Fatal(err)
	}

	// 增量深度信息订阅
	_, stopCh, err := wssc.WsDepthServe("BNBUSDT", wdh, errh)
	if err != nil {
		log.Fatal(err)
		return
	}

	go func() {
		// 设置2小时后停止订阅
		time.Sleep(2 * time.Hour)
		// 停止订阅增量深度信息
		stopCh <- struct{}{}
	}()

	// <-doneCh
	<-stopCh

}
